﻿using System;
using Microsoft.SharePoint;

namespace SPSiteColumnUsage
{
    internal static class Sample
    {
        public static void Run(string url, string fieldName)
        {
            using (SPSite site = new SPSite(url))
            {
                using (SPWeb web = site.OpenWeb())
                {
                    SPField field = web.Fields.GetFieldByInternalName(fieldName);

                    Console.WriteLine("Field: {0}", fieldName);
                    Console.WriteLine("==============================");

                    var usage = SPSiteColumnUsage.GetUsages(field);
                    foreach (var u in usage)
                    {
                        Console.WriteLine("Id: {0}", u.Id);
                        Console.WriteLine("Scope: {0}", u.Scope);
                        Console.WriteLine("ContentTypeId: {0}", u.ContentTypeId);
                        Console.WriteLine("IsUrlToList: {0}", u.IsUrlToList);
                        Console.WriteLine("Url: {0}", u.Url);
                        Console.WriteLine();
                    }
                }
            }
        }
    }
}
